package 多线程;

/**
 * @ClassName: ThreadSleepDemo
 * @Auther: Drawin
 * @Date: 2021/11/22 16:28
 * @Description:
 */

public class ThreadSleepDemo extends Thread{
    public void run(){//线程要执行的代码需要写到run方法里
        for (int i = 1; i <=3; i++) {
            System.out.println(Thread.currentThread().getName()+"第"+i+"次运行");
            try {
                Thread.sleep(1000);//让当前线程休眠1000毫秒，即1秒钟
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        ThreadSleepDemo t1 = new ThreadSleepDemo();//创建t1线程
        ThreadSleepDemo t2 = new ThreadSleepDemo();//创建t2线程
        t1.start();t2.start();//启动t1,t2线程
    }
}
